package com.think.teaching.controller;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.think.common.model.Result;
import com.think.teaching.model.BaseModel;
import com.think.teaching.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.Map;

public class BaseController<IService extends BaseService<IEntity>,IEntity extends BaseModel<IEntity>> {
	
	@Autowired
	protected BaseService<IEntity> baseService; 
	
	@Autowired
	protected BaseMapper<IEntity> baseMapper;
	
	
	
	Result AddNewData(@RequestBody()IEntity entity) {
		Result result = entity.CheckObjectComplete();
		if (result.getCode() == 10000 ) {
			return Result.success(baseService.AddNewData(entity));
		} 
		else {
			return result;
		}
	}
	
	Result DeleteData(Integer id) {
		return Result.success(baseService.DeleteData(id));
	}
	
	Result UpdateData(IEntity entity) {
		Result result = entity.CheckObjectComplete();
		if (result.getCode() == 10000 ) {
			return Result.success(baseService.UpdateData(entity));
		}
		else {
			return result;
		}
	}
	
	Result UserListData(Integer page,Integer count,Map<String, Object> filter,Boolean withoutBan) {
		return Result.success(baseService.ListData(page, count, filter,true));
	}
	
	Result AdminListData(Integer page,Integer count,Map<String, Object> filter,Boolean withoutBan) {
		return Result.success(baseService.ListData(page, count, filter,false));
	}
	
	Result ChangeDataState(Integer id) {
		return Result.success(baseService.ChangeDataState(id));
	}
	
	Result GetDataById(Integer id) {
		return Result.success(baseService.GetDataById(id));

	}
	

}
